package com.yeban.javase.day07.test3_stringbuilder;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/15
 *
 * 练习1：用StringBuilder把数组拼接成一个字符串
 * 举例：int[] arr = {1,2,3};  结果：[1, 2, 3]
 */
public class Test03 {
    public static void main(String[] args) {
        StringBuilder s1 = new StringBuilder();
        int[] arr ={1,2,3,4,5};
        s1.append("[");
        for (int i : arr) {
            if(i < arr.length) {
                s1.append(i + ", ");
            } else {
                s1.append(i + "]");
            }
        }

        // StringBuilder -> String
        String s2 = s1.toString();
        System.out.println(s2);
    }
}
